﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace TravelWeb.Base
{
    using TravelWeb.Common.Util;

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field |
        AttributeTargets.Parameter, AllowMultiple = false)]
    public abstract class CompareToOtherProperty : ScheduleValidationAttribute
    {
        public String PropertyName { get; set; }

        public CompareToOtherProperty()
        {
        }

        public CompareToOtherProperty(string propertyName)
        {
            PropertyName = propertyName;
        }

        public CompareToOtherProperty(string propertyName, Object objectContext)
        {
            PropertyName = propertyName;
            ObjectContext = objectContext;
        }

        private Type _OperandType = null;

        public Type OperandType
        {
            get
            {
                if (PropertyName != null && ObjectContext != null && _OperandType == null)
                {
                    Type type = ObjectContext.GetType();
                    _OperandType = ReflectorUtil.GetPropertyType(type,PropertyName);
                }
                return _OperandType;
            }
        }


    }
}